﻿Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.VisualBasic

Public Class frmGen
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnFile As System.Windows.Forms.Button
    Friend WithEvents lstFile As System.Windows.Forms.ListBox
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents txtSource As System.Windows.Forms.RichTextBox
    Friend WithEvents FolderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog
    Friend WithEvents mnuSave As System.Windows.Forms.ContextMenu
    Friend WithEvents txtNamespace As System.Windows.Forms.TextBox
    Friend WithEvents mnuBind As System.Windows.Forms.MenuItem
    Friend WithEvents mnuInverse As System.Windows.Forms.MenuItem
    Friend WithEvents mnuGenControl As System.Windows.Forms.MenuItem
    Friend WithEvents mnuOracleScript As System.Windows.Forms.MenuItem
   Friend WithEvents mnuXMLAddnode As System.Windows.Forms.MenuItem
   Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
   Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
   Friend WithEvents Label2 As System.Windows.Forms.Label
   Friend WithEvents Label1 As System.Windows.Forms.Label
   Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel
   Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
   Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
   Friend WithEvents GroupBox6 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox5 As System.Windows.Forms.GroupBox
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents txtControl As System.Windows.Forms.RichTextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Ten As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Button6 As System.Windows.Forms.Button
    Friend WithEvents Button5 As System.Windows.Forms.Button
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Public WithEvents txtConnection As System.Windows.Forms.TextBox

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.btnFile = New System.Windows.Forms.Button()
        Me.txtNamespace = New System.Windows.Forms.TextBox()
        Me.lstFile = New System.Windows.Forms.ListBox()
        Me.mnuSave = New System.Windows.Forms.ContextMenu()
        Me.mnuBind = New System.Windows.Forms.MenuItem()
        Me.mnuInverse = New System.Windows.Forms.MenuItem()
        Me.mnuGenControl = New System.Windows.Forms.MenuItem()
        Me.mnuOracleScript = New System.Windows.Forms.MenuItem()
        Me.mnuXMLAddnode = New System.Windows.Forms.MenuItem()
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
        Me.txtSource = New System.Windows.Forms.RichTextBox()
        Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog()
        Me.txtConnection = New System.Windows.Forms.TextBox()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.GroupBox4 = New System.Windows.Forms.GroupBox()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.Button4 = New System.Windows.Forms.Button()
        Me.Button3 = New System.Windows.Forms.Button()
        Me.Ten = New System.Windows.Forms.TextBox()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.GroupBox6 = New System.Windows.Forms.GroupBox()
        Me.GroupBox5 = New System.Windows.Forms.GroupBox()
        Me.Button6 = New System.Windows.Forms.Button()
        Me.Button5 = New System.Windows.Forms.Button()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.LinkLabel1 = New System.Windows.Forms.LinkLabel()
        Me.txtControl = New System.Windows.Forms.RichTextBox()
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox6.SuspendLayout()
        Me.GroupBox5.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnFile
        '
        Me.btnFile.Location = New System.Drawing.Point(9, 12)
        Me.btnFile.Name = "btnFile"
        Me.btnFile.Size = New System.Drawing.Size(145, 24)
        Me.btnFile.TabIndex = 0
        Me.btnFile.Text = "Fill"
        '
        'txtNamespace
        '
        Me.txtNamespace.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtNamespace.Location = New System.Drawing.Point(119, 44)
        Me.txtNamespace.Name = "txtNamespace"
        Me.txtNamespace.Size = New System.Drawing.Size(696, 20)
        Me.txtNamespace.TabIndex = 1
        Me.txtNamespace.Text = "defaultNameSpace"
        '
        'lstFile
        '
        Me.lstFile.ContextMenu = Me.mnuSave
        Me.lstFile.Dock = System.Windows.Forms.DockStyle.Fill
        Me.lstFile.Location = New System.Drawing.Point(3, 16)
        Me.lstFile.Name = "lstFile"
        Me.lstFile.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended
        Me.lstFile.Size = New System.Drawing.Size(154, 443)
        Me.lstFile.TabIndex = 3
        '
        'mnuSave
        '
        Me.mnuSave.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuBind, Me.mnuInverse, Me.mnuGenControl, Me.mnuOracleScript, Me.mnuXMLAddnode})
        '
        'mnuBind
        '
        Me.mnuBind.Index = 0
        Me.mnuBind.Text = "Bind Control"
        '
        'mnuInverse
        '
        Me.mnuInverse.Index = 1
        Me.mnuInverse.Text = "Inverse"
        '
        'mnuGenControl
        '
        Me.mnuGenControl.Index = 2
        Me.mnuGenControl.Text = "Gen Control"
        '
        'mnuOracleScript
        '
        Me.mnuOracleScript.Index = 3
        Me.mnuOracleScript.Text = "Oracle Script"
        '
        'mnuXMLAddnode
        '
        Me.mnuXMLAddnode.Index = 4
        Me.mnuXMLAddnode.Text = "Gen XML AddNode"
        '
        'txtSource
        '
        Me.txtSource.Dock = System.Windows.Forms.DockStyle.Top
        Me.txtSource.Location = New System.Drawing.Point(3, 16)
        Me.txtSource.Name = "txtSource"
        Me.txtSource.Size = New System.Drawing.Size(815, 358)
        Me.txtSource.TabIndex = 4
        Me.txtSource.Text = ""
        '
        'txtConnection
        '
        Me.txtConnection.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtConnection.Location = New System.Drawing.Point(119, 12)
        Me.txtConnection.Name = "txtConnection"
        Me.txtConnection.Size = New System.Drawing.Size(696, 20)
        Me.txtConnection.TabIndex = 6
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.GroupBox4)
        Me.GroupBox1.Controls.Add(Me.GroupBox3)
        Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Right
        Me.GroupBox1.Location = New System.Drawing.Point(166, 0)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(827, 554)
        Me.GroupBox1.TabIndex = 7
        Me.GroupBox1.TabStop = False
        '
        'GroupBox4
        '
        Me.GroupBox4.Controls.Add(Me.PictureBox1)
        Me.GroupBox4.Controls.Add(Me.txtSource)
        Me.GroupBox4.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupBox4.Location = New System.Drawing.Point(3, 118)
        Me.GroupBox4.Name = "GroupBox4"
        Me.GroupBox4.Size = New System.Drawing.Size(821, 433)
        Me.GroupBox4.TabIndex = 9
        Me.GroupBox4.TabStop = False
        '
        'PictureBox1
        '
        Me.PictureBox1.BackColor = System.Drawing.Color.White
        Me.PictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom
        Me.PictureBox1.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.PictureBox1.Image = Global.GenCode.My.Resources.Resources.Chu_Ky
        Me.PictureBox1.Location = New System.Drawing.Point(3, 346)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(815, 84)
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox1.TabIndex = 9
        Me.PictureBox1.TabStop = False
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.Add(Me.Button4)
        Me.GroupBox3.Controls.Add(Me.Button3)
        Me.GroupBox3.Controls.Add(Me.Ten)
        Me.GroupBox3.Controls.Add(Me.Button2)
        Me.GroupBox3.Controls.Add(Me.Label1)
        Me.GroupBox3.Controls.Add(Me.Label3)
        Me.GroupBox3.Controls.Add(Me.Label2)
        Me.GroupBox3.Controls.Add(Me.txtNamespace)
        Me.GroupBox3.Controls.Add(Me.txtConnection)
        Me.GroupBox3.Dock = System.Windows.Forms.DockStyle.Top
        Me.GroupBox3.Location = New System.Drawing.Point(3, 16)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(821, 102)
        Me.GroupBox3.TabIndex = 8
        Me.GroupBox3.TabStop = False
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(526, 73)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(116, 23)
        Me.Button4.TabIndex = 11
        Me.Button4.Text = "Tạo StoreProcedure"
        Me.Button4.UseVisualStyleBackColor = True
        Me.Button4.Visible = False
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(740, 73)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(75, 23)
        Me.Button3.TabIndex = 10
        Me.Button3.Text = "Save All File"
        Me.Button3.UseVisualStyleBackColor = True
        '
        'Ten
        '
        Me.Ten.Enabled = False
        Me.Ten.Location = New System.Drawing.Point(119, 75)
        Me.Ten.Name = "Ten"
        Me.Ten.Size = New System.Drawing.Size(607, 20)
        Me.Ten.TabIndex = 9
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(648, 73)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(78, 23)
        Me.Button2.TabIndex = 8
        Me.Button2.Text = "Save File"
        Me.Button2.UseVisualStyleBackColor = True
        Me.Button2.Visible = False
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(6, 15)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 13)
        Me.Label1.TabIndex = 7
        Me.Label1.Text = "Chuỗi Kết Nối"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(6, 78)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(54, 13)
        Me.Label3.TabIndex = 7
        Me.Label3.Text = "File Name"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(6, 47)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(64, 13)
        Me.Label2.TabIndex = 7
        Me.Label2.Text = "Namespace"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.GroupBox6)
        Me.GroupBox2.Controls.Add(Me.GroupBox5)
        Me.GroupBox2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupBox2.Location = New System.Drawing.Point(0, 0)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(166, 554)
        Me.GroupBox2.TabIndex = 8
        Me.GroupBox2.TabStop = False
        '
        'GroupBox6
        '
        Me.GroupBox6.Controls.Add(Me.lstFile)
        Me.GroupBox6.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupBox6.Location = New System.Drawing.Point(3, 89)
        Me.GroupBox6.Name = "GroupBox6"
        Me.GroupBox6.Size = New System.Drawing.Size(160, 462)
        Me.GroupBox6.TabIndex = 6
        Me.GroupBox6.TabStop = False
        '
        'GroupBox5
        '
        Me.GroupBox5.Controls.Add(Me.Button6)
        Me.GroupBox5.Controls.Add(Me.Button5)
        Me.GroupBox5.Controls.Add(Me.Button1)
        Me.GroupBox5.Controls.Add(Me.btnFile)
        Me.GroupBox5.Controls.Add(Me.LinkLabel1)
        Me.GroupBox5.Dock = System.Windows.Forms.DockStyle.Top
        Me.GroupBox5.Location = New System.Drawing.Point(3, 16)
        Me.GroupBox5.Name = "GroupBox5"
        Me.GroupBox5.Size = New System.Drawing.Size(160, 73)
        Me.GroupBox5.TabIndex = 5
        Me.GroupBox5.TabStop = False
        '
        'Button6
        '
        Me.Button6.Location = New System.Drawing.Point(90, 44)
        Me.Button6.Name = "Button6"
        Me.Button6.Size = New System.Drawing.Size(64, 23)
        Me.Button6.TabIndex = 6
        Me.Button6.Text = "Thoát"
        Me.Button6.UseVisualStyleBackColor = True
        '
        'Button5
        '
        Me.Button5.Location = New System.Drawing.Point(9, 44)
        Me.Button5.Name = "Button5"
        Me.Button5.Size = New System.Drawing.Size(75, 23)
        Me.Button5.TabIndex = 6
        Me.Button5.Text = "Kết Nối Lại"
        Me.Button5.UseVisualStyleBackColor = True
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(62, 12)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(51, 23)
        Me.Button1.TabIndex = 5
        Me.Button1.Text = "Kết Nối"
        Me.Button1.UseVisualStyleBackColor = True
        Me.Button1.Visible = False
        '
        'LinkLabel1
        '
        Me.LinkLabel1.AutoSize = True
        Me.LinkLabel1.Location = New System.Drawing.Point(116, 18)
        Me.LinkLabel1.Name = "LinkLabel1"
        Me.LinkLabel1.Size = New System.Drawing.Size(46, 13)
        Me.LinkLabel1.TabIndex = 4
        Me.LinkLabel1.TabStop = True
        Me.LinkLabel1.Text = "Website"
        Me.LinkLabel1.Visible = False
        '
        'txtControl
        '
        Me.txtControl.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.txtControl.Location = New System.Drawing.Point(0, 554)
        Me.txtControl.Name = "txtControl"
        Me.txtControl.Size = New System.Drawing.Size(993, 25)
        Me.txtControl.TabIndex = 5
        Me.txtControl.Text = ""
        '
        'Timer1
        '
        '
        'frmGen
        '
        Me.AcceptButton = Me.btnFile
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(993, 579)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.txtControl)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.MaximizeBox = False
        Me.Name = "frmGen"
        Me.ShowIcon = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Code Nhanh - Nguyễn Cảnh Hưng"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox4.ResumeLayout(False)
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox3.PerformLayout()
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox6.ResumeLayout(False)
        Me.GroupBox5.ResumeLayout(False)
        Me.GroupBox5.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private ds As DataSet
    Friend m_connect As String

    Private Sub FillList(ByVal dt As DataTable)
        lstFile.Items.Clear()
        Dim i As Integer
        For i = 0 To dt.Rows.Count - 1
            Dim tbl As String = dt.Rows(i)("TABLE_NAME").ToString()
            Dim str As String = tbl + "-Model"
            lstFile.Items.Add(str)
            str = tbl + "-Facade"
            lstFile.Items.Add(str)
            str = tbl + "-BO"
            lstFile.Items.Add(str)
            'str = tbl + "-GUI"
            'lstFile.Items.Add(str)
            'str = tbl + "-MVC"
            'lstFile.Items.Add(str)
        Next
    End Sub

    Private Sub btnFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFile.Click

        Try
            Dim dt As DataTable = LoadAllTable()
            FillList(dt)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub


    Private Sub lstFile_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstFile.SelectedIndexChanged
        Button3.Enabled = True
        Try
            Button1.Enabled = True
            Button2.Enabled = True
            If lstFile.SelectedItem Is Nothing Then Return

            Dim txt As String = lstFile.SelectedItem.ToString()
            Dim s() As String = txt.Split("-")
            Dim tablename As String = s(0).Trim()
            Ten.Text = tablename + s(1).Trim()
            Dim gen As New GenCode(tablename, txtNamespace.Text, txtConnection.Text)
            Select Case s(1).Trim()
                Case "Model"
                    txtSource.Text = gen.GetInfoAnhThao()
                Case "Facade"
                    txtSource.Text = gen.GetFacade()
                Case "BO"
                    txtSource.Text = gen.GetBO()

                    'Case "GUI"
                    '    txtSource.Text = gen.GetGUI()

                    'Case "MVC"
                    '    txtSource.Text = gen.GetMVC()
            End Select
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Function LoadAllTable() As DataTable
        Dim strSQL As String = "SELECT * FROM INFORMATION_SCHEMA.TABLES " _
            + " WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME<>'dtproperties' " _
            + " ORDER BY TABLE_NAME"
        Dim da As New SqlDataAdapter(strSQL, txtConnection.Text)
        Dim dt As New DataTable
        da.Fill(dt)
        Return dt
    End Function

    Private Sub frmTypedDataset_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'System.Diagnostics.Process.Start("http://canhhung.hui.vn/")
        Button3.Enabled = False
        Button1.Enabled = False
        Button2.Enabled = False
        Dim St() As String = IO.File.ReadAllLines("ChuoiKN.txt")
        m_connect = St(0)
        Dim ini As New IniFile(System.AppDomain.CurrentDomain.BaseDirectory + "gencode.ini")
        Dim nspace As String = ini.ReadValue("GENCODE", "namespace")
        txtNamespace.Text = nspace
        'MsgBox("http://canhhung.hui.vn/")
        Me.txtConnection.Text = m_connect

    End Sub

    Private Sub mnuBind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBind.Click
        Dim txt As String = lstFile.SelectedItem.ToString()
        Dim s() As String = txt.Split("-")
        Dim tablename As String = s(0).Trim()
        Dim gen As New GenCode(tablename, txtNamespace.Text, txtConnection.Text)
        txtControl.Text = gen.BindControl()
    End Sub

    Private Sub mnuInverse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuInverse.Click
        Dim content As String = txtControl.Text.Replace(vbCr, "").Replace(vbLf, "")
        Dim s() As String = content.Split(";")
        Dim txt As String = ""
        For i As Integer = 0 To s.Length - 1
            Dim a() As String = s(i).Split("=")
            If a.Length >= 2 Then
                txt += a(1).Trim() + " = " + a(0).Trim() + ";" + vbCrLf
            End If
        Next
        txtSource.Text = txt
    End Sub

    Private Sub mnuGenControl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuGenControl.Click
        Dim txt As String = lstFile.SelectedItem.ToString()
        Dim s() As String = txt.Split("-")
        Dim tablename As String = s(0).Trim()
        Dim gen As New GenCode(tablename, txtNamespace.Text, txtConnection.Text)
        txtControl.Text = gen.GenControl()
    End Sub

    Private Sub mnuOracleScript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOracleScript.Click
        Dim txt As String = lstFile.SelectedItem.ToString()
        Dim s() As String = txt.Split("-")
        Dim tablename As String = s(0).Trim()
        Dim gen As New GenCode(tablename, txtNamespace.Text, txtConnection.Text)
        txtControl.Text = gen.GenOracleScript()
    End Sub

    Private Sub mnuXMLAddnode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuXMLAddnode.Click
        Dim txt As String = lstFile.SelectedItem.ToString()
        Dim s() As String = txt.Split("-")
        Dim tablename As String = s(0).Trim()
        Dim gen As New GenCode(tablename, txtNamespace.Text, txtConnection.Text)
        txtControl.Text = gen.GenAddNodeXML()
    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As Object, ByVal e As EventArgs) Handles GroupBox1.Enter

    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As Object, ByVal e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        LinkLabel1.LinkVisited = True
        System.Diagnostics.Process.Start("http://canhhung.hui.vn/")

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Ten.Text = "KetNoi"
        If lstFile.SelectedItem Is Nothing Then Return

        Dim txt As String = lstFile.SelectedItem.ToString()
        Dim s() As String = txt.Split("-")
        Dim tablename As String = s(0).Trim()
        Dim gen As New GenCode(tablename, txtNamespace.Text, txtConnection.Text)
        txtSource.Text = gen.Get_Chuoi()

    End Sub

    Public Function DirExists(ByVal OrigFile As String)
        Dim fs
        fs = CreateObject("Scripting.FileSystemObject")
        DirExists = fs.folderexists(OrigFile)
    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'If (DirExists("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_BLL") = False) Then
        '    MkDir("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_BLL")
        'End If
        'If (DirExists("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_DAL") = False) Then
        '    MkDir("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_DAL")
        'End If
        'If (DirExists("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_Entities") = False) Then
        '    MkDir("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_Entities")
        'End If
        'If (DirExists("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text) = False) Then
        '    MkDir("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text)
        'End If
        'Dim hung As String = Microsoft.VisualBasic.Right(Ten.Text, 3)
        'Dim hung1 As String = Microsoft.VisualBasic.Right(Ten.Text, 8)
        'Dim hung2 As String = Ten.Text.Replace("_GUI", "")
        'If (hung = "DAL") Then
        '    txtSource.SaveFile("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_DAL\" + Ten.Text + ".cs", RichTextBoxStreamType.PlainText)
        'End If
        'If (hung = "BLL") Then
        '    txtSource.SaveFile("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_BLL\" + Ten.Text + ".cs", RichTextBoxStreamType.PlainText)
        'End If
        'If (hung = "GUI") Then
        '    txtSource.SaveFile("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "\" + hung2 + ".cs", RichTextBoxStreamType.PlainText)
        'End If
        'If (hung1 = "Entities") Then
        '    txtSource.SaveFile("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_Entities\" + Ten.Text + ".cs", RichTextBoxStreamType.PlainText)
        'End If
        'If (Ten.Text = "KetNoi") Then
        '    txtSource.SaveFile("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_DAL\" + Ten.Text + ".cs", RichTextBoxStreamType.PlainText)
        'End If
        'MsgBox("Success!")
        'System.Diagnostics.Process.Start("C:\CanhHungIT\" + txtNamespace.Text)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim i As Integer

        For i = 0 To lstFile.Items.Count - 1
            Dim txt As String = lstFile.Items(i).ToString()
            Dim s() As String = txt.Split("-")
            Dim tablename As String = s(0).Trim()
            Ten.Text = tablename + s(1).Trim()
            Dim gen As New GenCode(tablename, txtNamespace.Text, txtConnection.Text)
            Select Case s(1).Trim()
                Case "Model"
                    txtSource.Text = gen.GetInfoAnhThao()
                Case "Facade"
                    txtSource.Text = gen.GetFacade()
                Case "BO"
                    txtSource.Text = gen.GetBO()
                    'Case "GUI"
                    '    txtSource.Text = gen.GetGUI()
                    'Case "MVC"
                    '    txtSource.Text = gen.GetMVC()

            End Select
            'If (DirExists("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_MVC") = False) Then
            '    MkDir("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_MVC")
            'End If
            If (DirExists("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "BO") = False) Then
                MkDir("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "BO")
            End If
            If (DirExists("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "Facade") = False) Then
                MkDir("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "Facade")
            End If
            If (DirExists("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "Model") = False) Then
                MkDir("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "Model")
            End If
            'If (DirExists("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text) = False) Then
            '    MkDir("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text)
            'End If
            Dim hung As String = Microsoft.VisualBasic.Right(Ten.Text, 3)
            Dim hung1 As String = Microsoft.VisualBasic.Right(Ten.Text, 5)
            Dim hung11 As String = Microsoft.VisualBasic.Right(Ten.Text, 2)
            Dim hung12 As String = Microsoft.VisualBasic.Right(Ten.Text, 6)

            'Dim hung2 As String = Ten.Text.Replace("_GUI", "")
            'hung2 = hung2.Trim()
            'If (hung = "MVC") Then
            '    txtSource.SaveFile("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_MVC\" + Ten.Text + ".cs", RichTextBoxStreamType.PlainText)
            'End If

            If (hung12 = "Facade") Then
                txtSource.SaveFile("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "Facade\" + Ten.Text + ".cs", RichTextBoxStreamType.PlainText)
            End If
            If (hung11 = "BO") Then
                txtSource.SaveFile("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "BO\" + Ten.Text + ".cs", RichTextBoxStreamType.PlainText)
            End If
            'If (hung = "GUI") Then
            '    txtSource.SaveFile("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "\" + hung2 + ".cs", RichTextBoxStreamType.PlainText)
            'End If
            If (hung1 = "Model") Then
                txtSource.SaveFile("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "Model\" + Ten.Text + ".cs", RichTextBoxStreamType.PlainText)
            End If
        Next
        'Button1_Click(sender, e)
        'If (Ten.Text = "KetNoi") Then
        '    txtSource.SaveFile("C:\CanhHungIT\" + txtNamespace.Text + "\" + txtNamespace.Text + "_DAL\" + Ten.Text + ".cs", RichTextBoxStreamType.PlainText)
        'End If
        MsgBox("Success!")
        System.Diagnostics.Process.Start("C:\CanhHungIT\" + txtNamespace.Text)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        System.Diagnostics.Process.Start("Store.exe")
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Application.Exit()
        System.Diagnostics.Process.Start("http://canhhung.hui.vn/")
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Application.Exit()
        System.Diagnostics.Process.Start("KetNoi.exe")
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        

    End Sub
End Class
